/**
 * 2017年5月31日
 */
package jdk.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author Alex
 *
 */
class Product{
	int k = 0;
	
}
class Factory{
	int k = 0;
	AtomicInteger ai = new AtomicInteger(0);
	Product get(){
		int temp = k;
		temp +=1;
		try {
			ai.addAndGet(1);
			Thread.currentThread().sleep(10);
		} catch (InterruptedException e) {
			
			e.printStackTrace();
		}
		k = temp;

		return new Product();
	}
	
	
}
public class ThreadTest {
	public static void main(String[] args) throws InterruptedException {
		final Factory f = new Factory();
		ExecutorService ec = Executors.newFixedThreadPool(10);
		for(int i =0;i<100;i++){
			ec.execute(()->{
				System.out.println(f.get());
			});
		}
		ec.shutdown();
		ec.awaitTermination(100, TimeUnit.SECONDS);
		System.out.println(f.k);
		System.out.println(f.ai.get());
	}
}
